﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataSource;
using Exchange;


namespace Trader
{
    class Position
    {
        Dictionary<string, int> posDict;
        public Position()
        {
            posDict = new Dictionary<string, int>();
        }

        public void Update(Deal dl)
        {
            if(dl.type == OrderType.Cancel)
            {
                return;
            }
            if (dl.side == TradeSide.Buy)
            {
                if (posDict.ContainsKey(dl.code))
                {
                    posDict[dl.code] += dl.volume;
                }
                else
                {
                    posDict[dl.code] = dl.volume;
                }
            }
            else
            {
                posDict[dl.code] -= dl.volume;
            }

        }

        public int GetPosition(string code)
        {
            return posDict[code];
        }

        public bool IsPosition(string code)
        {
            if (posDict.ContainsKey(code))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

    }
}
